FROM ccapnljh.mirror.aliyuncs.com/library/php:7.1.3-fpm

ENV TZ Asia/Shanghai

# Debian环境更换阿里云镜像
ADD sources.list /etc/apt/sources.list 
RUN apt-get update -y

# 一些工具
RUN apt-get install -y zip unzip apt-utils

# iconv, mcrypt and gd 扩展
RUN apt-get install -y zlib1g zlib1g-dev \
        libfreetype6-dev \
        libjpeg62-turbo-dev \
        libmcrypt-dev \
        libpng12-dev \
    && docker-php-ext-install -j$(nproc) iconv mcrypt \
    && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
    && docker-php-ext-install -j$(nproc) gd

# pdo mysqli 扩展
RUN docker-php-ext-install pdo_mysql && docker-php-ext-install mysqli

# Opcache 扩展
RUN docker-php-ext-configure opcache --enable-opcache && docker-php-ext-install opcache

# redis 扩展
RUN pecl install redis-3.1.2 \
    && docker-php-ext-enable redis 

# memcached 扩展
RUN apt-get install -y libmemcached-dev zlib1g-dev \
    && pecl install memcached-3.0.3 \
    && docker-php-ext-enable memcached

# xdebug 扩展
RUN pecl install xdebug-2.5.3 \
    && docker-php-ext-enable xdebug

# xhprof 扩展 pecl上xhprof的php7不支持
RUN apt-get install -y git \
    && mkdir -p /usr/src/php/ext \
    && cd /usr/src/php/ext \
    && git clone https://github.com/tideways/php-profiler-extension.git \
    && cd php-profiler-extension \
    && phpize \
    && ./configure \
    && make \
    && make install \
    && docker-php-ext-enable tideways

# PHP config
ADD php.ini /usr/local/etc/php/php.ini
ADD php-fpm.conf /usr/local/etc/php-fpm.conf
ADD php-fpm.d/* /usr/local/etc/php-fpm.d/


# composer
ADD composer.phar /usr/local/bin/composer
RUN chmod 755 /usr/local/bin/composer
RUN composer config -g repo.packagist composer https://packagist.phpcomposer.com

# deployer
ADD deployer.phar /usr/local/bin/dep
RUN chmod 755 /usr/local/bin/dep
RUN chmod +x /usr/local/bin/dep


# 安装supervisor openssh-server
RUN apt-get install -y supervisor openssh-server

# www-data用户ssh可登陆
RUN mkdir -p /var/run/sshd /home/www-data
RUN usermod -s /bin/bash www-data
RUN chown -R www-data.www-data /home/www-data  
RUN usermod -d /home/www-data -u 33 www-data                                                                
RUN echo 'www-data:pw123456' | chpasswd

# supervisor 启动服务 docker提倡的是一容器一服务，一容器多服务为fat container，有没有更好的解决方式？
RUN mkdir -p /var/log/supervisor
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
CMD ["/usr/bin/supervisord"]


